<?php
/**
 * User Account components
 * 
 * No redirection nor database manipulation ( insert, update, delete ) here
 * 
 * 
 */
class userAccountComponents extends myFrontModuleComponents
{

  public function executeShowDashboard()
  {
    $this->userAccount = $this->getUser()->getDmUser();
    $this->userRecentOrders =CustomarOrderTable::getInstance()->createQuery()
            ->where('customer_id = ?',$this->getUser()->getDmUser()->getId())
            ->orderBy('created_at DESC')
            ->limit(4)
            ->execute();
  }

  public function executeShowAccountInfo()
  {
    $this->userAccount = $this->getUser()->getDmUser();
    $this->form = $this->forms['UserAccountInfo'];
  }

  public function executeShowAddressBook(dmWebRequest $request)
  {
    $this->editAddress= false;
    if($request->hasParameter('address_edit'))
        $this->editAddress= true;
    $this->form = $this->forms['ShowAddressBook'];
    $this->userAccount = $this->getUser()->getDmUser();
  }

  public function executeShowOrders(dmWebRequest $request)
  {
    $order_id = $request->getParameter('order_id');
    $this->userOrder = CustomarOrderTable::getInstance()->find($order_id);
  }
  public function executeShowWishList()
  {
    $this->userAccount = $this->getUser()->getDmUser();
  }

  public function executeNewsletterSubscription()
  {
    // Your code here
      $this->isSubscribe = false;
      $userNewsLetter = LrSubscriberTable::getInstance()->findOneByEmail($this->getUser()->getDmUser()->getEmail());
      if($userNewsLetter)
          $this->isSubscribe = true;
  }

  public function executeListOrders()
  {
    $query = CustomarOrderTable::getInstance()->createQuery()
            ->where('customer_id = ?',$this->getUser()->getDmUser()->getId())
            ->orderBy('created_at DESC')->limit(20);
    
    $this->userAccountPager = $this->getPager($query);
  }

  public function executeListProductComments()
  {
    $query = DmCommentTable::getInstance()->createQuery()
            ->where('author_email = ?',$this->getUser()->getDmUser()->getEmail());
    
    $this->userCommentPager = $this->getPager($query);
  }


}
